package com.ctsi.hangye.app.rest;

import com.ctsi.framework.common.response.UnifiedResponse;
import com.ctsi.framework.security.util.SecurityUtil;
import com.ctsi.hangye.dto.GzhyDTO;
import com.ctsi.hangye.service.GzhyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HangyeController {

    @Autowired
    private GzhyService gzhyService;

    /**
     * 关注行业
     */
    @PostMapping(value = "/hangye/add-guanzhu")
    public UnifiedResponse<Void> guanzhu(@RequestParam(value = "hangyeId") String hangyeId,
                                         @RequestParam(value = "scopeId",required = false) String scopeId){
        String userId = SecurityUtil.getUser().getUserId();
        gzhyService.addGz(userId,hangyeId);
        return UnifiedResponse.ok();
    }

    /**
     * 关注行业列表
     */
    @PostMapping(value = "/hangye/list-guanzhu")
    public UnifiedResponse<List<GzhyDTO>> guanzhuList(){
        List<GzhyDTO> list = gzhyService.findGzhyDTOList(SecurityUtil.getUser().getUserId());
        return UnifiedResponse.ok(list);
    }

    /**
     * 删除关注的行业
     */
    @PostMapping(value = "/hangye/del-guanzhu")
    public UnifiedResponse<Void> delGuanzhu(@RequestParam(value = "id") String id){
        gzhyService.delGZ(id);
        return UnifiedResponse.ok();
    }


}
